chalk = require('chalk')
Redis = require('ioredis')
sendCommand = Redis::sendCommand

Redis::sendCommand = (command)->
  begin = new Date()
  log = =>
      t = [
        chalk.green("redis "+@_name)
        chalk.gray("<")
        chalk.greenBright command.name
        chalk.blueBright command.args.join(" ")
      ]
      cost = (new Date() - begin)
      if cost > 10
            t.push chalk.gray((cost / 1000) + " 秒")
      console.log  t.join(" ")
  try
      r = sendCommand.apply(@, arguments)
  finally
      log()
  return r


do ->
    mod = require '../../db/redis.coffee'
    for k,v of mod
        mod[k]._name = k.toLowerCase()
